/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.RenameAccountRequest;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class RenameAccount
/*     */   extends AdminDocumentHandler
/*     */ {
/*  46 */   private static final String[] TARGET_ACCOUNT_PATH = { "id" };
/*     */   
/*  48 */   protected String[] getProxiedAccountPath() { return TARGET_ACCOUNT_PATH; }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean domainAuthSufficient(Map<String, Object> context)
/*     */   {
/*  55 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  63 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  69 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  70 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  72 */     RenameAccountRequest req = (RenameAccountRequest)JaxbUtil.elementToJaxb(request);
/*  73 */     String id = req.getId();
/*  74 */     String newName = req.getNewName();
/*     */     
/*  76 */     Account account = prov.get(Key.AccountBy.id, id, zsc.getAuthToken());
/*  77 */     defendAgainstAccountHarvesting(account, Key.AccountBy.id, id, zsc, Rights.Admin.R_renameAccount);
/*     */     
/*  79 */     String oldName = account.getName();
/*     */     
/*     */ 
/*  82 */     checkAccountRight(zsc, account, Rights.Admin.R_renameAccount);
/*     */     
/*     */ 
/*  85 */     checkDomainRightByEmail(zsc, newName, Rights.Admin.R_createAccount);
/*     */     
/*  87 */     Mailbox mbox = Provisioning.onLocalServer(account) ? MailboxManager.getInstance().getMailboxByAccount(account) : null;
/*  88 */     prov.renameAccount(id, newName);
/*  89 */     if (mbox != null) {
/*  90 */       mbox.renameMailbox(oldName, newName);
/*     */     }
/*     */     
/*  93 */     ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "RenameAccount", "name", oldName, "newName", newName }));
/*     */     
/*     */ 
/*     */ 
/*  97 */     account = prov.get(Key.AccountBy.id, id, true, zsc.getAuthToken());
/*  98 */     if (account == null) {
/*  99 */       throw ServiceException.FAILURE("unable to get account after rename: " + id, null);
/*     */     }
/* 101 */     Element response = zsc.createElement(AdminConstants.RENAME_ACCOUNT_RESPONSE);
/* 102 */     ToXML.encodeAccount(response, account);
/* 103 */     return response;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 108 */     relatedRights.add(Rights.Admin.R_renameAccount);
/* 109 */     relatedRights.add(Rights.Admin.R_createAccount);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/RenameAccount.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */